package com.fqxiny.lease.web.admin.custom.config;

import com.fqxiny.lease.web.admin.custom.converter.StringToBaseEnumConverterFactory;
import com.fqxiny.lease.web.admin.custom.interceptors.LoginIntercepter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author : 戚欣扬
 * @code : SpringMVC配置类
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {
    @Autowired
    private StringToBaseEnumConverterFactory stringToBaseEnumConverterFactory;
    @Autowired
    private LoginIntercepter loginIntercepter;
    @Value("${web.admin.path-patterns.include}")
    private String [] includePath;
    @Value("${web.admin.path-patterns.exclude}")
    private String [] excludePath;

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(stringToBaseEnumConverterFactory);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginIntercepter).addPathPatterns(includePath).excludePathPatterns(excludePath);
    }
}


